/*
 *
 * (c) Copyright Ascensio System Limited 2010-2023
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/


using ASC.Common.Data;
using ASC.Common.Data.Sql;
using ASC.Mail.Server.Core.Dao.Interfaces;
using ASC.Mail.Server.Core.DbSchema;
using ASC.Mail.Server.Core.DbSchema.Interfaces;
using ASC.Mail.Server.Core.DbSchema.Tables;
using ASC.Mail.Server.Core.Entities;

namespace ASC.Mail.Server.Core.Dao
{
    public class DomainDao : BaseDao, IDomainDao
    {
        protected static ITable table = new MailServerTableFactory().Create<DomainTable>();

        public DomainDao(IDbManager dbManager)
            : base(table, dbManager)
        {
        }

        public int Save(Domain domain)
        {
            var query = new SqlInsert(DomainTable.TABLE_NAME, true)
                .InColumnValue(DomainTable.Columns.DOMAIN, domain.Name)
                .InColumnValue(DomainTable.Columns.DESCRIPTION, domain.Description)
                .InColumnValue(DomainTable.Columns.CREATED, domain.Created)
                .InColumnValue(DomainTable.Columns.MODIFIED, domain.Modified)
                .InColumnValue(DomainTable.Columns.ACTIVE, domain.Active);

            var result = Db.ExecuteNonQuery(query);
            return result;
        }

        public int Remove(string domain)
        {
            var query = new SqlDelete(DomainTable.TABLE_NAME)
                .Where(DomainTable.Columns.DOMAIN, domain);

            var result = Db.ExecuteNonQuery(query);
            return result;
        }
    }
}